<template>
<div>
    <van-nav-bar
  :title="comment.reply_count>0 ? `${comment.reply_count}条回复` : '暂无回复'"
>
<van-icon
slot="left"
name="cross"
@click="$emit('close')"
 />
</van-nav-bar>
<div class="scroll-wrap">
  <!-- 当前评论项 -->
<comment-item :comment="comment" />
<!-- /当前评论项 -->

<!-- 评论的回复列表 -->
<van-cell title="全部回复"/>
<comment-list
:list="commentList"
:source="comment.com_id"
 type="c"/>
<!-- /评论的回复列表 -->
</div>
<!-- 底部区域 -->
<div class="post-wrap">
  <van-button size="small" round class="post-btn"
  @click="isPostShow = true"
  >写评论</van-button>
</div>
<!-- /底部区域 -->

<!-- 发布评论 -->
<van-popup position="bottom"  v-model="isPostShow">
  <CommentPost
  :target="comment.com_id"
  @post-success="onPostSuccess"
  />
<!-- /发布评论 -->

</van-popup>
</div>
</template>

<script>
import CommentItem from './comment-item'
import CommentList from './comment-list'
import CommentPost from './commen-post'
export default {
  components: {
    CommentItem,
    CommentList,
    CommentPost
  },
  data () {
    return {
      isPostShow: false,
      commentList: []
    }
  },
  name: 'RePly',
  props: {
    comment: {
      type: Object,
      required: true
    }
  },
  methods: {
    onPostSuccess (data) {
      // 更新回复的数量
      // eslint-disable-next-line vue/no-mutating-props
      this.comment.reply_count++

      // 关闭弹层
      this.isPostShow = false

      // 将最新回复的内容展示到列表的顶部
      this.commentList.unshift(data.new_obj)
    }
  }
}
</script>

<style scoped lang="less">
// 滚动容器
.scroll-wrap{
  position: fixed;
  top: 92px;
  left: 0;
  right: 0;
  bottom: 88px;
  overflow-y:auto
}
.post-wrap{
  position: fixed;
  bottom:0;
  left: 0;
  right: 0;
  height: 88px;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: #fff;
  border: 1px solid #d8d8d8;
  .post-btn{
    width: 60%;
  }
}

</style>
